package com.zb.Task;

import com.alibaba.fastjson.JSON;
import com.zb.config.RabbitConfig;
import com.zb.entity.Exchangescore;
import com.zb.service.ExchangescoreService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyTask {

    @Autowired
    private ExchangescoreService exchangescoreService;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Scheduled(cron = "0/5 * * * * *")
    public void task() throws Exception{
        System.out.println("=======》开启定时任务");
        List<Exchangescore> listByMap = exchangescoreService.getExchangescoreListByMap(null);
        for (Exchangescore score : listByMap) {
            System.out.println("======>"+score);
            if(score!=null){
                rabbitTemplate.convertAndSend(RabbitConfig.SCORE_ONE_EXCHAGE,RabbitConfig.SCORE_ONE_ROUTING, JSON.toJSONString(score));
            }
        }
    }
}
